<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>赛事管理页面</title>

    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script type="text/javascript" src="js/jquery-3.0.0.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script type="text/javascript" src="js/bootstrap.min.js"></script>

    <script type="text/javascript">
        $(function(){
            $.ajax({
                url: "/api/v1/game/info",
                type: "GET",
                data:{},
                crossDomain: true, // 跨域，即不同域名、端口号可以访问
                contentType: 'application/json; charset=utf-8',  // 请求体数据格式 json字符串
                success:function(d){
                    //alert("ok")
                    if(d['status']==500){
                        alert(d['data']);
                    }
                    if(d['status']==200){
                        show(d['data']);
                    }
                },
                error:function(){},
                dataType:"json"
            });

            function show(data){
/*              // 循环列出
                for (var i = 0; i < data.length; i++) {
                    var context = "<tr><td>"+data[i]['bookId']+"</td>"+"<td>"+data[i]['gamId']+"</td>"+"<td>"+data[i]['gamName']+"</td>"+ "<td>"+data[i]['gameIntroduction']+"</td>"+
                        "<tr><td>"+data[i]['gameSponsor']+"</td>"+"<td>"+data[i]['gameTime']+"</td>"+"<td>"+data[i]['gameType']+"</td>"+ "<td>"+data[i]['remark']+"</td>"+
                        "<td><button id='audit"+i+"' class='btn btn-warning btn-primary' type='button' style='margin-right:5px'>审核</button>" +
                        "<button id='delete"+i+"' class='btn btn-danger btn-primary' type='button'>删除</button></td></tr>";

                    $('#game').append(context)
                }*/

                // 遍历每场赛事，i索引 j赛事对象
                $.each(data,function (i,j){
                    // 每场赛事的按钮id必须区分开
                    $("#game").append("<tr><td>"+j['bookId']+"</td>"+"<td>"+j['gameId']+"</td>"+"<td>"+j['gameName']+"</td>"+
                        "<td>"+j['gameIntroduction']+"</td>"+ "<td>"+j['gameSponsor']+"</td>"+ "<td>"+j['gameTime']+"</td>"+
                        "<td>"+j['periods']+"</td>"+"<td>"+j['gameType']+"</td>"+ "<td>"+j['remark']+"</td>"+
                        "<td><button id='audit"+i+"' class='btn btn-warning btn-primary' type='button' style='margin-right:5px'>审核</button>"
                        +"<button id='delete"+i+"' class='btn btn-danger btn-primary' type='button'>删除</button></td></tr>");

                    $("#audit"+i).click(function(){
                        $.ajax({
                            url: "/api/v1/role",
                            type: "PATCH",
                            data: JSON.stringify(requestData), // data:发送数据，JSON.stringify()转成json字符串
                            crossDomain: true, // 跨域，即不同域名、端口号可以访问
                            contentType: 'application/json; charset=utf-8',  // 请求体数据格式 json字符串

                            success:function(d){
                                //alert("ok")
                                if(d['status']==500){
                                    alert(d['data']);
                                }
                                if(d['status']==200){
                                    alert("审核成功");
                                    window.opener.location.href = window.opener.location.href;
                                    window.close();
                                }
                            },
                            error:function(){},
                            dataType:"json"
                        });
                        window.open ("book_audit.html?bookId="+j['bookId']+"&&gamId="+j['gamId']+"&&roleCode="+j['roleCode']+
                            "roleSort="+j['roleSort']+"&&roleType="+j['roleType']+"&&roleDesc="+j['roleDesc']+"&&remark="+j['remark'],
                            "newwindow", "height=400px, width=400, top=200px, left=500px, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no")&nbsp;
                    });

                    $("#delete"+i).click(function(){
                        disp_confirm(j['roleId']);
                    });
                });

            }

            //删除跳出 确认窗口，确定才会继续操作
            function disp_confirm(gameId)
            {
                var r=confirm("确定要删除赛事吗？")
                if (r==true){
                    //alert(gameId);
                    $.ajax({
                        url: "/api/v1/game/info"+gameId,
                        type: "DELETE",
                        data:{},
                        crossDomain: true, // 跨域，即不同域名、端口号可以访问
                        contentType: 'application/json; charset=utf-8',  // 请求体数据格式 json字符串
                        success:function(d){
                            if(d['status']==200){
                                alert("删除成功");
                                window.location.href = window.location.href;
                            }
                            if(d['status']==500){
                                alert(d['data']);
                            }
                        },
                        error:function(){},
                        dataType:"json"
                    });

                }else {}
            }
        });

    </script>
</head>
<body>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12" style="height: 400px">
                <table class="table">
                    <thead>
                    <tr>
                        <th>
                            预约编号
                        </th>
                        <th>
                            赛事编号
                        </th>
                        <th>
                            赛事名称
                        </th>
                        <th>
                            赛事简介
                        </th>
                        <th>
                            赛事主办单位
                        </th>
                        <th>
                            赛事举办日期
                        </th>
                        <th>
                            当天场次
                        </th>
                        <th>
                            赛事类型
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                    </thead>
                    <tbody id="game">
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</body>
</html>